﻿namespace P3_StudentInfo;

public class StudentManager
{
    //存储学生列表
    public List<Student> students = new List<Student>();

    //添加学生
    public void AddStudent(string name, int age, double score)
    {
        try
        {
            students.Add(new Student(name, age, score));
            Console.WriteLine($"Added student {name}");
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
        
    }
    //删除学生
    public void DeleteStudent(string name)
    {
        students.Remove(students.Find(student => student.Name == name));
        Console.WriteLine($"Deleted student {name}");
    }
    //查找学生
    public void FindStudent(string name)
    {
        Student student = students.FirstOrDefault(student => student.Name == name);
        Console.WriteLine($"Found student {name}:{student}");
    }
    
    //显示所有学生信息
    public void PrintStudents()
    {
        students.ForEach(student => Console.WriteLine($"{student}"));
    }
}